using System.Windows.Forms;
using NUnit.Framework;
using ShadeTree.Binding.Lists;

namespace ShadeTree.Binding.Tests.Lists
{
    [TestFixture]
    public class PicklistTester
    {
        #region Setup/Teardown

        [SetUp]
        public void SetUp()
        {
        }

        #endregion

        [Test]
        public void GetValueWhenSelectedItemIsNull()
        {
            var array = new[] {"a", "b", "c"};
            var list = new Picklist<string>(array);

            var box = new ComboBox();
            Assert.IsNull(box.SelectedItem);
            Assert.IsNull(list.GetValue(null));
        }


        [Test]
        public void GetValueWhenSelectedItemIsNullAndValueMemberIsNotNull()
        {
            var array = new[] {"a", "b", "c"};
            var list = new Picklist<string>(array);
            list.ValueMember = "something";

            var box = new ComboBox();
            Assert.IsNull(box.SelectedItem);
            Assert.IsNull(list.GetValue(null));
        }

        [Test]
        public void SortListAndMoveItemsToTopOfList()
        {
            var array = new[] {"a", "b", "c", "d", "e", "f"};
            var list = new Picklist<string>(array);

            Assert.AreEqual("a", list.Items[0]);
            Assert.AreEqual("b", list.Items[1]);

            list.MoveItemsToTopOfList(new[] {"d", "f"});

            Assert.AreEqual("d", list.Items[0]);
            Assert.AreEqual("f", list.Items[1]);
            Assert.AreEqual("a", list.Items[2]);
            Assert.AreEqual("b", list.Items[3]);
        }

        [Test]
        public void StringPicklist()
        {
            var array = new[] {"a", "b", "c"};
            var list = new Picklist<string>(array);

            var box = new ComboBox();

            list.Fill(box);

            var actual = new string[box.Items.Count];
            box.Items.CopyTo(actual, 0);

            Assert.AreEqual(array, actual);
        }

        [Test]
        public void StringPicklistGetDisplay()
        {
            var array = new[] {"a", "b", "c"};
            var list = new Picklist<string>(array);

            var box = new ComboBox();

            list.Fill(box);

            list.SelectForDisplay(box, "b");
            Assert.AreEqual("b", box.SelectedItem);
            Assert.AreEqual("b", list.GetDisplay(box));
        }

        [Test]
        public void StringPicklistSelectDisplay()
        {
            var array = new[] {"a", "b", "c"};
            var list = new Picklist<string>(array);

            var box = new ComboBox();

            list.Fill(box);

            list.SelectForDisplay(box, "b");
            Assert.AreEqual("b", box.SelectedItem);
        }
    }
}